package com.cyanite.playlv2api.types;

import com.cyanite.playlv2api.util.ParcelUtils;

import android.os.Parcel;
import android.os.Parcelable;

public class SearchResult implements PlayLv2Type, Parcelable{

    private Group<TripMini> mTrips;
    private Group<TaskMini> mTasks;
    private boolean mIsTrip;

    public SearchResult(){

    }
    private SearchResult(Parcel in) {
        mIsTrip =  Boolean.valueOf(ParcelUtils.readStringFromParcel(in));
        
        int numTrips = in.readInt();
        if(numTrips > 0){
            mTrips = new Group<TripMini>();
            for (int i = 0; i < numTrips; i++) {
                TripMini trip = in.readParcelable(User.class.getClassLoader());
                mTrips.add(trip);
            }
        }

        int numTasks = in.readInt();
        if(numTasks > 0){
            mTasks = new Group<TaskMini>();
            for (int i = 0; i < numTasks; i++) {
                TaskMini task = in.readParcelable(User.class.getClassLoader());
                mTasks.add(task);
            }
        }
    }
    public static final Parcelable.Creator<SearchResult> CREATOR = new Parcelable.Creator<SearchResult>() {
        public SearchResult createFromParcel(Parcel in) {
            return new SearchResult(in);
        }

        @Override
        public SearchResult[] newArray(int size) {
            return new SearchResult[size];
        }
    };
    public void setIsTrip(boolean isTrip){
        mIsTrip = isTrip;
    }

    public boolean getIsTrip(){
        return mIsTrip;
    }
    public void setTrips(Group<TripMini> trips){
        mTrips = trips;
    }

    public Group<TripMini> getTrips(){
        return mTrips;
    }

    public void setTasks(Group<TaskMini> tasks){
        mTasks = tasks;
    }

    public Group<TaskMini> getTasks(){
        return mTasks;
    }
    @Override
    public int describeContents() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        ParcelUtils.writeStringToParcel(out, String.valueOf(mIsTrip));
        if (mTrips != null) {
            out.writeInt(mTrips.size());
            for (int i = 0; i < mTrips.size(); i++) {
                out.writeParcelable(mTrips.get(i), flags);
            }
        } else {
            out.writeInt(0);
        }

        if (mTasks != null) {
            out.writeInt(mTasks.size());
            for (int i = 0; i < mTasks.size(); i++) {
                out.writeParcelable(mTasks.get(i), flags);
            }
        } else {
            out.writeInt(0);
        }
    }
}
